package org.wlldTest;


import java.io.FileInputStream;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.security.spec.PKCS8EncodedKeySpec;

public class Main {
    public static void main(String[] args) {
        try {
            // 加载KeyStore
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            char[] password = "123456".toCharArray();
            keyStore.load(new FileInputStream("D:\\a.jks"), password);
            // 获取别名
            String alias = "socket.wlhlwl.com";

            // 获取私钥
            Key key = keyStore.getKey(alias, password);
            if (key instanceof PrivateKey) {
                PrivateKey privateKey = (PrivateKey) key;
                System.out.println("Private Key: " + privateKey);
            }

            // 获取证书
            Certificate cert = keyStore.getCertificate(alias);
            if (cert != null) {
                System.out.println("Certificate: " + cert);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
